<?php
session_start();

if(!isset($_SESSION['id'])){
	header('Location:login.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
</head>

<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">升级管理</a></li>
    <li><a href="#">升级方式</a></li>			
    </ul>
    </div>
	
    <div class="formbody">
    <div class="formtitle"><span>基本信息</span></div>
	<?php
	
	    $way=$_POST['way'];
		 
	    //得到about_shenji.conf内容
	   $array=array();
	   $handle = fopen("about_shenji.conf", "r");
	   while (!feof ($handle)){
		$buffer  = fgets($handle);
		array_push($array,$buffer);
	     
      }
	  #得到配置文件中的信息
	  $get_way=$array[0];
	  $get_status=$array[1];
	  $get_version=$array[2];
	  
	  $rel_way=substr($get_way,4);
	  $rel_status=substr($get_status,7);
	  $rel_version=substr($get_version,8);
	
	
	  if($way==0){  //自动升级,把信息写入到文件中去(只改变way)
	     $filename="about_shenji.conf";
		 $xie_way="way=0";
		 $xie_status="status=".$rel_status;
		 $xie_version="version=".$rel_version;
		 file_put_contents("about_shenji.conf",$xie_way."\n".$xie_status.$xie_version);
		 echo "操作成功!";
	  }
	  if($way==1){ //手动升级(way与status)
		 //判断是否有文件
	     if(!empty($_FILES['file']['tmp_name'])){  //选择了文件
			   if($_FILE["file"]["error"]>0){
				 echo "error".$_FILE["file"]["error"]."<br/>";
			   }else{
				   
				//判断是否有正在升级的,有升级的不允许上传
				if($rel_status!=1){
					  $file_name = $_FILES['file']['name'];
					 //判断上传升级包小于当前版本不允许上传
					  $file_version=substr($file_name,0,-14);
					  $file_version1=$file_version*100;
					  $rel_version1=$rel_version*100;
					  
					  if($file_version1<$rel_version1){
						  
						  echo "上传升级包低于当前版本,无法上传!";
						   
					  }else{
						  
						 //$new_file=($rel_version+0.01)."_update.tar.gz";
						 move_uploaded_file($_FILES["file"]["tmp_name"],"/var/www/html/upload/shenjibao/".$file_name);
						 #把信息写入到about_shenji.conf文件中去
						 $filename="about_shenji.conf";
						 $xie_way="way=1";
						 $xie_status="status=1";
						 $xie_version="version=".$rel_version;
						 file_put_contents("about_shenji.conf",$xie_way."\n".$xie_status."\n".$xie_version);
						 echo "操作成功!";
						  
					  }
				
					 
				}else{
					
					echo "有正在升级的升级包,请稍候再试";
					
				}

			}
			
	   }else{   //没有文件
			 #把信息写入到about_shenji.conf文件中去
			 $filename="about_shenji.conf";
			 $xie_way="way=1";
			 $xie_status="status=0";
			 $xie_version="version=".$rel_version;
			 file_put_contents("about_shenji.conf",$xie_way."\n".$xie_status."\n".$xie_version);
			 echo "操作成功";
	   }
	
	 }
	?>
    </div>
</body>

</html>





